@extends('layout.default')

@section('layout.content')
<div class="row">
  <div class="col-xs-12 col-md-8 col-md-offset-2">
    <form class="form-horizontal" id="staff-update" autocomplete="off">
    <div class="form-group">
        <label class="col-sm-4 control-label no-padding-right"> 账号：</label>
        <div class="col-sm-4">
            <p class="control-label align-left"><b>{{$staff->username}}</b></p>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-4 control-label no-padding-right">  名称：</label>
        <div class="col-sm-4">
            <p class="control-label align-left"><b>{{$staff->name}}</b></p>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-4 control-label no-padding-right" for="oldpwd">  原密码：</label>
        <div class="col-sm-4">
            <input type="password" class="form-control" name="oldpwd" placeholder="原密码" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-4 control-label no-padding-right" for="newpwd">  新密码：</label>
        <div class="col-sm-4">
            <input type="password" class="form-control" id="newpwd" name="newpwd" placeholder="6位以上数字和字母" />
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-4 control-label no-padding-right" for="rnewpwd">  密码确认：</label>
        <div class="col-sm-4">
            <input type="password" class="form-control" name="rnewpwd" placeholder="再次输入新密码"/>
        </div>
    </div>


    <div class="form-group">
       <label class="col-sm-4 control-label no-padding-right"> </label>
      <div class="col-sm-4">
          <button type="submit" class="btn btn-primary submit">
            <i class="ace-icon fa fa-check"></i>
            <span class="">确定</span>
          </button>
      </div>
    </div>

  </form>
  </div>
</div>

@stop

@section('javascript')
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"></script>
<script src="{{URL::asset('/assets/js/jquery-validate-methods.js')}}"></script>
<script src="//cdn.bootcss.com/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script type="text/javascript">
  $(function() {
    $("input[name='oldpwd']").focus();

    $("#staff-update").validate({

      onfocusout: false,
      onkeyup: false,

      rules: {
        oldpwd: {required: true },
        newpwd: {required: true,minlength:6},
        rnewpwd: {required: true,minlength:6,equalTo: "#newpwd"},
      },
      messages: {
        oldpwd: {required: "请输入原密码"},
        newpwd: {required: "请填写新密码",minlength:"密码长度不正确"},
        rnewpwd: {required: "请填写确认密码",minlength:"密码长度不正确",equalTo: "两次输入的密码不一致"},
      },
 	showErrors: function (errorMap, errorList) {
          $.each(errorList, function (i, v) {
              layer.tips(v.message, v.element, { tips:3, time: 2000 });
              //$(v.element).closest('.weui-cell').addClass('weui-cell_warn');
              return false;
          });
      },

      submitHandler: function(form) {
        var uri = '{{route('system.staff.chgpwd',$staff->id)}}';
        $.post(uri, {
          '_token': $("input[name='_token']").attr('value'),
          'oldpwd': $("input[name='oldpwd']").val(),
          'newpwd': $("input[name='newpwd']").val(),
          'rnewpwd': $("input[name='rnewpwd']").val(),
          '_method': 'put',
          'is_submit': true
        }, function(data) {
          console.log(data);
           layer.msg(data.message, { time:1000,shift: -1 },function(){
            if(data.status === true && data.url != null ){
              $(window).attr('location', data.url);
            }
          });

        },'json').error(function(data){
          layer.msg(data.responseJSON.message);
        });
      }

    });

    /*$('.submit').on('click', function() {

      var uri = '{{route('system.staff.update',$staff->id)}}';

      $.post(uri, {
        '_token':$("input[name='_token']").attr('value'),
        'oldpwd': $("input[name='oldpwd']").val(),
        'newpwd': $("input[name='newpwd']").val(),
        'rnewpwd': $("input[name='rnewpwd']").val(),
        '_method': 'put',
        'is_submit': true
      }, function(data) {
        layer.msg(data.message, { shift: -1 },function(){
          if(data.status === true && data.url != null ){
            $(window).attr('location', data.url);
          }
        });

      },'json').error(function(data){
        layer.msg(data.responseJSON.message);
      });

    });*/


  });
</script>
@stop
